package com.common.weibolib;

import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.message.BasicHeader;

import android.content.Context;
import android.text.TextUtils;

import com.common.android.utils.httpRequest.AutoLoginHttpRequest;
import com.common.android.utils.httpRequest.IHttpRequest;
import com.product.android.business.config.Configuration;

/**
 * 
 * ClassName:AutoWeiboLoginHttpRequest
 * Function: 重写HttpHeader
 * Reason:	 TODO ADD REASON
 * 
 * @author   huangszh		
 * @version  
 * @since    Ver 1.1
 * @Date	 2014	2014-1-28		下午2:46:18
 *
 * @see
 */
public class AutoWeiboLoginHttpRequest extends AutoLoginHttpRequest{

	private static IHttpRequest _autoWeiboInstance;	// 定义自己的instance,用父类的在某些特殊情况可能导致转型错误
	 
	private AutoWeiboLoginHttpRequest(Context ctx, int appid, int type) {
		 super(ctx,appid,type);
    }
	  
    /**
     * 
     * @n<b>函数名称</b>     :getInstance
     * @brief
     * @see
     * @since    Ver 1.1
     * @param  @param ctx
     * @param  @param appid
     * @param  @param type
     * @param  @return
     * @return IHttpRequest
     * @<b>作者</b>          :  huangszh
     * @<b>创建时间</b>      :  2014-1-28下午2:42:36
     */
    public static IHttpRequest getInstance(Context ctx, int appid, int type) {
        if (_autoWeiboInstance == null) {
        	_autoWeiboInstance = new AutoWeiboLoginHttpRequest(ctx, appid, type);
        }
        return _autoWeiboInstance;
    }
    
    @Override
    public void setHttpHeader(HttpRequestBase request) {
    	super.setHttpHeader(request);
    	request.addHeader(new BasicHeader("WEIBO-API-KEY",Configuration.WEIBO_APP_KEY));
    	request.addHeader(new BasicHeader("WEIBO-API-SECRET",Configuration.WEIBO_APP_SECRET));
        request.addHeader(new BasicHeader("UAP-SID", GlobalSetting.getSid(mContext)));
        // 暂时明星APP有要求加这个头部
        if(!TextUtils.isEmpty(Configuration.CLOUNDID)){
        	request.addHeader(new BasicHeader("CLOUD-ID",Configuration.CLOUNDID));
        }
    }
}
